let nowDate = moment().format('YYYY-M-D')

function dateDiff(data1, data2 = nowDate) {
  // 判断传入参数是否正确
  if(!(moment(data1).isValid()) || !(moment(data2).isValid())) {
    throw new Error('function dateDiff argument error 请输入正确的时间格式~~');
  }

  // 得到我的时间数组 [2020,10,01] | [10,01]
  let temp1Arr = data1.trim().split(' ')[0].split('-')
  let temp2Arr = data2.trim().split(' ')[0].split('-')
  let nowDateArr = nowDate.trim().split(' ')[0].split('-')

  if(temp1Arr.length == 2) {
    if(temp1Arr[0] > nowDateArr[1] || ( temp1Arr[0] == nowDateArr[1] && temp1Arr[1] > nowDateArr[2])) {
      temp1Arr.unshift(nowDateArr[0] -1)
    } else {
      temp1Arr.unshift(nowDateArr[0])
    }
  }

  if(temp2Arr.length == 2) {
    if(temp2Arr[0] > nowDateArr[1] || ( temp2Arr[0] == nowDateArr[1] && temp2Arr[1] > nowDateArr[2])) {
      temp2Arr.unshift(nowDateArr[0] -1)
    } else {
      temp2Arr.unshift(nowDateArr[0])
    }
  }

  // diff 操作步骤
  temp1Arr[1]--
  temp2Arr[1]--
  let a = moment(temp1Arr);
  let b = moment(temp2Arr);
  return b.diff(a, 'days')
}

let ret = dateDiff('2022-12-11 11:11')

console.log(ret)

// var a = moment([2009, 12, 29]);
// var b = moment([2007, 12, 28]);
// let temp = a.diff(b, 'days') // 1

// console.log(temp)

